<template>
  <div class="container">
    <!-- <div class="container-1200"> -->
      <div class="admin-container">
      <div class="flexWithJusBetween mg-B20">
        <div class="title">项目汇总信息</div>
      </div>

      <div v-show="queryType == false">
        <el-form ref="warehouseForm" label-width="80px" :inline="true">
          <el-form-item label="起始日期">
            <el-date-picker
      v-model="query.startDate"
      value-format="yyyy-MM-dd"
      type="year"
      placeholder="选择年度"
      :picker-options="pickerOptions">
    </el-date-picker>
          </el-form-item>
          <el-button
            style="margin-left: 10px"
            icon="el-icon-search"
            type="primary"
            @click="submitQuery"
            >查询
          </el-button>
          <el-button
            style="margin-left: 10px"
            icon="el-icon-refresh-right"
            type="info"
            @click="resetQuery"
            >重置
          </el-button>
        </el-form>
      </div>

      <statisticsTable :tableData="tableData" ></statisticsTable>

      <!-- <el-tabs v-model="status" @tab-click="handleClick">
        <el-tab-pane label="待审" name="1">
          
        </el-tab-pane>
        <el-tab-pane label="已审" name="2">
         <statisticsTable :tableData="tableData" ></statisticsTable>
        </el-tab-pane>
        <el-tab-pane label="驳回" name="3">
          <statisticsTable :tableData="tableData" ></statisticsTable>
        </el-tab-pane>
      </el-tabs> -->
    </div>
  </div>
</template>

<script>
import { validUsername } from "@/utils/validate";
import utils from "@/utils/utils.js";
import statisticsTable from "./statisticsTable";
import { find as companyFind,list as companyList } from "@/api/adminCompany";
import { list as projectList,statistics } from "@/api/adminProject";

export default {
  components: {statisticsTable},
  name: "project",
  data() {
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error("密码不能少于6位"));
      } else {
        callback();
      }
    };
    return {
      pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },},
      queryType: false,
      query: {
        startDate:"",
      },
      tableData:{},
      statisticsInfo:{},
      status:'1',

      //字典信息
      dict:{},
      projectStatusDict:[],

      projectStatusDictPromise:"",
    };
  },
  watch: {
    $route: {
      handler: function (route) {},
      immediate: true,
    },
  },

  created() {
  },

  mounted() {
    // if (this.$route.query) {
    //   this.companyId = this.$route.query.companyId;
    //   this.companyFind(this.companyId);
    // }
    let _this = this
    _this.getStatistics()
    
  },

  destroyed() {},

  methods: {
    //获取项目列表
    getStatistics(companyId) {
      let _this = this
      let params = new URLSearchParams();
      params.append("status", 2);
      params.append("startDate", _this.query.startDate);
      statistics(params)
        .then((res) => {
          console.log("statistics成功获取数据--", res);
          if (res.type == "success") {
            this.tableData = res.data;
          }
        })
        .catch((err) => {
          this.$message.error(err.msg);
        });
    },

    //tab切换
    handleClick(tab, even){
      console.log('tab--',this.status);
      this.getStatistics()
    },

    //条件查询
    submitQuery() {
      this.getStatistics();
    },

    //条件查询
    resetQuery() {
      this.query = {
        startDate:"",
      },
        this.getStatistics();
    },

    //获取公司列表
    getCmpanyList() {
      companyList().then((res) => {
        console.log("获取公司信息res--", res);
        if (res.type == "success") {
          this.companyList = res.data.data;
        }
      });
    },

    //新增项目
    addProject() {
      this.$router.push({
        path: "/project/add",
        query: { companyId: this.companyId },
      });
    },

    //查看项目
    audit(data) {
      this.$router.push({
        path: "/project/audit",
        query: { projectId: data.id,companyId: this.companyId },
      });
    },

    viewProjectActivity(data) {
      this.$router.push({
        path: "/projectActivity/auditList",
        query: { projectId: data.id },
      });
    },

    viewProjectExecute(data) {
      this.$router.push({
        path: "/projectExecute/auditList",
        query: { projectId: data.id },
      });
    },

    //编辑项目
    editProject(data) {
      this.$router.push({
        path: "/project/edit",
        query: { projectId: data.id, companyId: this.companyId },
      });
    },

    //项目月报表
    projectExecute(data) {
      this.$router.push({
        path: "/projectExecute/list",
        query: { projectId: data.id, companyId: this.companyId },
      });
    },

    //项目活动表
    projectActivity(data) {
      this.$router.push({
        path: "/projectActivity/list",
        query: { projectId: data.id, companyId: this.companyId },
      });
    },

    //获取公司信息
    companyFind(id) {
      companyFind(id).then((res) => {
        console.log("获取公司信息res--", res);
        if (res.type == "success") {
          this.companyInfo = res.data.company;
        }
      });
    },

    projectStatusFormate(data) {
      return utils.selectDictLabel(this.projectStatusDict, data);
    },
  },
};
</script>

<style lang="scss" scoped>

.el-pagination {
  display:block;
}
</style>
